package com.stylefeng.guns.modular.payroll;

import com.stylefeng.guns.modular.system.model.Payroll;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

public  class MapToPayroll {


    /**
     * 将excel工资表的数据转换成工资表对应的实体类
     * @param list
     * @param payTime
     * @author laoyu
     * @Date 2018-07-24
     * @return
     * @throws Exception
     */
    public static   List<Payroll> mapToPayroll(List<Map<String,Object>> list,String payTime)throws Exception{
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("YYYY-MM-DD");
        Date nowDate = new Date();
        List<Payroll> payrollList = new ArrayList<>();
        for (int i = 0; i < list.size()-2; i++) {//表格解析时会多解析两条空数据
            Payroll payroll = new Payroll();
            Map<String, Object> map = list.get(i);
            payroll.setUsercode(Integer.parseInt(map.get("usercode").toString()));
            payroll.setUsername(map.get("username").toString());
            payroll.setPlatform(map.get("platform").toString());
            payroll.setEntryTime(map.get("entryTime").toString());
            payroll.setBasicSalary(Double.parseDouble(map.get("basicSalary").toString()));
            payroll.setBonus(Double.parseDouble(map.get("bonus").toString()));
            payroll.setAttendanceDays(Integer.parseInt(map.get("attendanceDays").toString()));
            payroll.setActualBasicSalary(Double.parseDouble(map.get("actualBasicSalary").toString()));
            payroll.setActualBonus(Double.parseDouble(map.get("actualBonus").toString()));
            payroll.setPerformanceBonus(Double.parseDouble(map.get("performanceBonus").toString()));
            payroll.setCommission(Double.parseDouble(map.get("commission").toString()));
            payroll.setNorepairBonus(Double.parseDouble(map.get("norepairBonus").toString()));
            payroll.setOtherSubsidies(Double.parseDouble(map.get("otherSubsidies").toString()));
            payroll.setLeaveDays(Integer.parseInt(map.get("leaveDays").toString()));
            payroll.setLeaveDeduction(Double.parseDouble(map.get("leaveDeduction").toString()));
            payroll.setLateArrivals(Integer.parseInt(map.get("lateArrivals").toString()));
            payroll.setLetaDeduction(Double.parseDouble(map.get("letaDeduction").toString()));
            payroll.setOtherDeduction(Double.parseDouble(map.get("otherDeduction").toString()));
            payroll.setAdvancePiso(Double.parseDouble(map.get("advancePiso").toString()));
            payroll.setAdvanceRmb(Double.parseDouble(map.get("advanceRmb").toString()));
            payroll.setRealRmb(Double.parseDouble(map.get("realRmb").toString()));
            payroll.setSendPsio(Double.parseDouble(map.get("sendPsio").toString()));
            payroll.setRoomSupplement(Double.parseDouble(map.get("roomSupplement").toString()));
            payroll.setRealPiso(Double.parseDouble(map.get("realPiso").toString()));
            payroll.setRemarks(map.get("remarks").toString());
            payroll.setPayTime(payTime);
            payroll.setCreattime(nowDate);
            payroll.setUpdatetime(nowDate);

           payrollList.add(payroll);
        }
        return payrollList;
    }

}
